﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Windows.Controls;
using JMT.Data;

namespace JMT.Controls.Commands
{
    public class AddDiagramCommand : ICommand
    {
        private ContextMenu _contextMenu;
        private MenuItem _menuItem;

        public AddDiagramCommand(ContextMenu contextMenu, MenuItem menuItem)
        {
            _contextMenu = contextMenu;
            _menuItem = menuItem;
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            IJContainer<JDiagram> jContainer = _contextMenu.DataContext as IJContainer<JDiagram>;

            JDiagram jDiagram = new JDiagram();
            jDiagram.Id = Guid.NewGuid();
            jDiagram.Name = string.Format("{0}{1}", JConstString.TDiagram, jContainer.GetUniqueIndex<JDiagram>());
            JData.Current.AddModel<JDiagram>(jContainer, jDiagram);
        }
    }
}
